package org.example.demo.controller.userController;

import io.swagger.annotations.ApiOperation;
import org.example.demo.dto.OrderGenParam;
import org.example.mbg.model.ProductByOrder;
import org.example.demo.service.userService.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "/user/order")
public class UserOrderController {

    @Autowired
    private UserOrderService userOrderService;

    @ApiOperation("添加订单")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public String userAddOrder(@RequestBody List<OrderGenParam> orderGenParam) {
        System.out.println(orderGenParam);
        return userOrderService.generateOrder(orderGenParam);
    }

    @ApiOperation("显示订单")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public List<ProductByOrder> userListOrder(Long userId) {
        return userOrderService.list(userId);
    }

    @ApiOperation("确认收货")
    @RequestMapping(value = "/receive", method = RequestMethod.POST)
    @ResponseBody
    public String receive(@RequestBody Long orderId) {
        return userOrderService.receive(orderId);
    }


    @ApiOperation("单件商品直接生成订单")
    @RequestMapping(value = "/buyone", method = RequestMethod.POST)
    @ResponseBody
    public String userAddOrder(@RequestBody OrderGenParam orderGenParam) {
        return userOrderService.buyOne(orderGenParam);
    }

    @ApiOperation("获取订单信息")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseBody
    public ProductByOrder userAddOrder(Long id, Long user_id) {
        return userOrderService.get(id, user_id);
    }
}
